package zeebe.multiInstance;

import io.vertx.core.json.JsonObject;
import io.zeebe.client.ZeebeClient;
import io.zeebe.client.api.response.ActivatedJob;
import io.zeebe.client.api.worker.JobClient;
import io.zeebe.client.api.worker.JobHandler;

public class MultiSequentialJobWorkerHandler implements JobHandler {
    ZeebeClient zeebeClient;

    public MultiSequentialJobWorkerHandler(ZeebeClient client) {
        this.zeebeClient = client;
    }

    @Override
    public void handle(JobClient client, ActivatedJob job) throws Exception {
        System.out.println("开始执行multiSequentialJobWorker");

        JsonObject data = new JsonObject(job.getVariables());
        int item = data.getInteger("item");
        int result=item*2;
        System.out.println("输入item="+item+",乘以2得到值result="+result);

        JsonObject output = new JsonObject()
                .put("result", result);
        client.newCompleteCommand(job.getKey())
                .variables(output.encode())
                .send()
                .join();
    }
}
